﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Public;

namespace DAL
{
    public class NguoiDungDAL
    {
        public static bool KiemTraDangNhap(string TenDangNhap,string MatKhau)
        {
            string chuoi="select * from NguoiDung where TenDangNhap="+"'"+TenDangNhap+"'"+" and MatKhau="+"'"+MatKhau+"'";
            var nguoidung = Common.db.ExecuteStoreQuery<NguoiDungPublic>(@chuoi);
            if (nguoidung.Count() > 0)
            {
                return true;
            }
            return false;
        }
        public static List<NguoiDungPublic> LoadNguoiDung()
        {
            var nd = Common.db.ExecuteStoreQuery<NguoiDungPublic>(@"select * from NguoiDung");
            return nd.ToList();
        }
        public static void InsertNguoiDung(NguoiDungPublic _nd)
        { 
            NguoiDung nd=new NguoiDung();
            nd.MaND = _nd.MaND;
            nd.TenDangNhap = _nd.TenDangNhap;
            nd.MatKhau = _nd.MatKhau;
            nd.HoTen = _nd.HoTen;
            nd.MaPX = _nd.MaPX;
            nd.ChucVu = _nd.ChucVu;
            //nd.SoDienThoai = _nd.SoDienThoai;
            Common.db.AddToNguoiDungs(nd);
            Common.db.SaveChanges();
        }
        public static void DeleteNguoiDung(int MaND)
        {
            var nd = Common.db.ExecuteStoreQuery<NguoiDungPublic>(@"delete from NguoiDung where MaND=" + MaND);

        }
    }
}
